<%@ page import="com.fuful.domain.Product" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<table  border="1" align="center">
    <tr>
        <td>产品编码</td>
        <td>产品名称</td>
        <td>产品类型</td>
        <td>产品价格</td>
        <td>操作</td>
    </tr>
    <%
        //获取共享对象
        List<Product> data = (ArrayList)session.getAttribute("productdata");
        for (Product p : data) {
    %>
    <tr>
        <td><%= p.getPcode()%></td>
        <td><%= p.getPname()%></td>
        <td><%= p.getPtid().getPtname()%></td>
        <td><%= p.getPprice()%></td>
        <td>添加</td>
    </tr>
    <%
        }
    %>
</table>
<button type="button" id="first" class="btn btn-primary">首页</button>
<button type="button" id="pre" class="btn btn-success">上一页</button>
<button type="button" id="next" class="btn btn-danger">下一页</button>
<button type="button"  id="end" class="btn btn-warning">末页</button>

</body>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script>
    let pn=1;
    let ps=3;
    let next,pre,pc;
    let tj="";
    $(function () {
        queryData(1,ps,tj);
        $("#first").click(function(){
            queryData(1,ps,tj);
        });
        $("#pre").click(function(){
            queryData(pre,ps,tj);
        });
        $("#next").click(function(){
            queryData(next,ps,tj);
        });
        $("#end").click(function(){
            queryData(pc,ps,tj);
        });
    })

    function queryData(pn1,ps1,c) {
        $.ajax({
            type:"POST",
            url:"product",
            data:"method=querySome&pageNumber="+pn1+"&pageSize="+ps1+c,//参数
            dataType:"json",
            success:function (msg) {
                //console.log(msg);//控制台打印
                pn = msg.pageNumber;
                ps = msg.pageSize;
                pre = msg.pre;
                next = msg.next;
                end = msg.pageCount;

                $("#total").text(msg.total);
                $("#pageCount").text(msg.pageCount);
                let trs="";
                $.each(msg.rows,function (i,product) {
                    trs+="<tr><td>"+(msg.start+i+1)+"</td>" +
                        "<td>"+product.pcode+"</td>" +
                        "<td>"+product.pname+"</td>" +
                        "<td>"+product.ptype+"</td>" +
                        "<td>"+product.pprice+"</td>" +
                        "<td>"+加入购物车+"</td></tr>"
                });
                $("#data").html(trs);

            }
        })

    }

</script>

</html>
